#include <iostream>
#include <omp.h>
#include <thread>
using namespace std;

void testParallel()
{
    std::cout << "cpu核心数：" << omp_get_num_procs() << std::endl;
#pragma omp parallel num_threads(2)
    {
        cout << "thread id:" << omp_get_thread_num() << "Hello World!" << endl;
    }

    std::this_thread::sleep_for(std::chrono::seconds(1));

    std::cout << "并行域二" << std::endl;
    int i = 1;
    int j = 2;
    int k = 3;
#pragma omp parallel num_threads(2) firstprivate(j) shared(k) reduction(+ : i)
    {
        std::cout << "初始值：" << i << "-" << j << "-" << k << endl;
#pragma omp barrier
        i = omp_get_thread_num(); // 0 1
        j += omp_get_thread_num();
        k += omp_get_thread_num();
#pragma omp barrier
        std::cout << "线程id：" << omp_get_thread_num() << "-" << i << "-" << j << "-" << k << endl;
    }

    std::cout << "终值：" << i << "-" << j << "-" << k << endl;
}

int main()
{

    #pragma omp parallel num_threads(4)
    {   
   
        #pragma omp sections
        {
            #pragma omp section
            {
                std::cout<<"thread id:" << omp_get_thread_num() << "section 1" << endl;
                std::this_thread::sleep_for(std::chrono::seconds(1));
            }
            #pragma omp section
            {
                std::cout<<"thread id:" << omp_get_thread_num() << "section 2" << endl;
                std::this_thread::sleep_for(std::chrono::seconds(1));
            }

            #pragma omp section
            {
                std::cout<<"thread id:" << omp_get_thread_num() << "section 3" << endl;
                std::this_thread::sleep_for(std::chrono::seconds(1));
            }


        }
    }




    return 0;
}